from itertools import ifilterfalse
from continuedfraction import cfroot_gen, cfvalues
from calc import is_square

def diophantine(d):
    """ Returns a minimal solution (x,y) in x for the equation x**2 - D * y**2 = 1."""
    for (x,y) in cfvalues(cfroot_gen(d)):
        if x * x - d * y * y == 1:
            return (x, y, d)
        
limit = 1000
print max([diophantine(d) for d in ifilterfalse(is_square, range(2, limit + 1))])
